
package Service;

import model.Student;
import model.Course;
import model.Score;
import model.Teacher;

import java.io.*;
import java.util.*;

public class FileDataManager {
    private static final String STUDENT_FILE = "students.txt";
    private static final String COURSE_FILE = "courses.txt";
    private static final String SCORE_FILE = "scores.txt";
    private static final String TEACHER_FILE = "teachers.txt";  // Add teacher file

    /**
     * 加载所有学生数据
     */
    public Map<String, Student> loadStudents() {
        Map<String, Student> students = new HashMap<>();
        // Implementation of loading student data
        return students;
    }

    /**
     * 加载所有课程数据
     */
    public Map<String, Course> loadCourses() {
        Map<String, Course> courses = new HashMap<>();
        // Implementation of loading course data
        return courses;
    }

    /**
     * 加载所有成绩数据
     */
    public List<Score> loadScores(Map<String, Student> students, Map<String, Course> courses) {
        List<Score> scores = new ArrayList<>();
        // Implementation of loading score data
        return scores;
    }

    /**
     * 加载所有教师数据
     */
    public Map<String, Teacher> loadTeachers() {
        Map<String, Teacher> teachers = new HashMap<>();
        try (BufferedReader br = new BufferedReader(new FileReader(TEACHER_FILE))) {
            String line;
            while ((line = br.readLine()) != null) {
                String[] teacherData = line.split(",");
                String id = teacherData[0].trim();
                String name = teacherData[1].trim();
                String password = teacherData[2].trim();
                String title = teacherData[3].trim();
                Teacher teacher = new Teacher(id, name, password, title);
                teachers.put(id, teacher);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return teachers;
    }
}
